﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="ShopPowerTemplate.ShoppingCartViewPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ShopPowerTemplate"
    xmlns:common="using:ShopPowerTemplate.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:ShopPowerTemplate.Data"
    mc:Ignorable="d">

    <Page.Resources>
        <common:StringFormatConverter x:Key="StringFormatConverter" />
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid Grid.ColumnSpan="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyleCustom}" />
            <StackPanel x:Name="headerStackPanel" Grid.Column="1" Orientation="Horizontal">
                <Border x:Name="headerBorder" Height="80" Padding="0,0,20,0" Margin="0,0,20,0" BorderThickness="0,0,1,0" BorderBrush="{StaticResource ApplicationHeaderForegroundThemeBrush}">
                    <Image x:Name="headerImage" Source="ms-appx:///Assets/LogoShop.png" Stretch="Uniform" />
                </Border>
                <TextBlock x:Name="pageTitle" Text="{Binding Title}" IsHitTestVisible="false" Style="{StaticResource PageHeaderTextStyle}" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
            </StackPanel>
        </Grid>

        <!-- Horizontal scrolling grid used in most view states -->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemsGridView"
            AutomationProperties.Name="Items"
            Grid.Column="1"
            Grid.Row="1"
            ItemsSource="{Binding CartList}"
            ItemTemplate="{StaticResource ShoppingCartItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="False"
            IsItemClickEnabled="False" 
            />

        <!-- Vertical scrolling list only used when snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemsListView"
            AutomationProperties.Name="Items"
            TabIndex="1"
            Visibility="Collapsed"
            Margin="0"
            Padding="20,0,0,0"
            ItemsSource="{Binding CartList}"
            ItemTemplate="{StaticResource SnappedShoppingCartItemTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="False"
            IsItemClickEnabled="False" 
            Grid.ColumnSpan="3" 
            Grid.Row="1"
            />

        <Grid x:Name="summaryPanel" Grid.Column="2" Grid.Row="1" MinWidth="280" HorizontalAlignment="Stretch" Margin="0,0,40,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Border Style="{StaticResource ShoppingCartSummaryHeaderBorder}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Artículos:</TextBlock>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding ItemsTotal, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
                </Grid>
            </Border>
            <Border Grid.Row="1" Style="{StaticResource ShoppingCartSummaryBorder}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Envío:</TextBlock>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding ShippingCost, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
                </Grid>
            </Border>
            <Border Grid.Row="2" Style="{StaticResource ShoppingCartSummaryBorder}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Descuentos:</TextBlock>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Discount, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
                </Grid>
            </Border>
            <Border Grid.Row="3" Style="{StaticResource ShoppingCartSummaryBorder}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Impuestos:</TextBlock>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Taxes, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
                </Grid>
            </Border>
            <Border Grid.Row="4" Style="{StaticResource ShoppingCartSummaryFooterBorder}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Total:</TextBlock>
                    <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Total, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
                </Grid>
            </Border>
            <Button Click="ProcederAlPago" 
                    Grid.Row="5" 
                    HorizontalAlignment="Stretch" 
                    FontWeight="Normal"
                    FontSize="32"
                    Padding="20"
                    Margin="-3,0">Proceder al pago</Button>
            <Button Click="GoBack" 
                    IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" 
                    Grid.Row="6" 
                    FontSize="26.667" 
                    FontWeight="Normal"
                    HorizontalAlignment="Stretch"
                    Margin="-3,0">Seguir comprando</Button>
        </Grid>

        <Grid x:Name="summaryPanelSnapped" 
              Grid.Row="2" 
              Grid.ColumnSpan="3"
              Margin="20"
              MinWidth="280" 
              HorizontalAlignment="Stretch" 
              Visibility="Collapsed">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Artículos:</TextBlock>
                <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding ItemsTotal, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
            </Grid>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Envío:</TextBlock>
                <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding ShippingCost, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
            </Grid>
            <Grid Grid.Row="2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Descuentos:</TextBlock>
                <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Discount, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
            </Grid>
            <Grid Grid.Row="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Impuestos:</TextBlock>
                <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Taxes, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
            </Grid>
            <Grid Grid.Row="4">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock 
                        Style="{StaticResource ShoppingCartDetailTextStyle}">Total:</TextBlock>
                <TextBlock 
                        Style="{StaticResource ShoppingCartPriceTextStyle}" 
                        Text="{Binding Total, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                        HorizontalAlignment="Right"
                        Grid.Column="1"></TextBlock>
            </Grid>
            <Button Click="ProcederAlPago" 
                    Grid.Row="5" 
                    HorizontalAlignment="Stretch" 
                    FontWeight="Normal"
                    FontSize="26.667"
                    Padding="5"
                    Margin="-3,0">Proceder al pago</Button>
            <Button Click="GoBack" 
                    IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" 
                    Grid.Row="6" 
                    FontSize="20" 
                    FontWeight="Normal"
                    HorizontalAlignment="Stretch"
                    Margin="-3,0">Seguir comprando</Button>
        </Grid>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait" />

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedButtonStyleCustom}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="itemGridView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="itemListView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="summaryPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="summaryPanelSnapped">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(StackPanel.Orientation)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0,10"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Style)" Storyboard.TargetName="pageTitle">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedTitleTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerImage">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="40,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
